﻿using NLog;
using p2pMessaging.Interfaces;

namespace p2pMessaging.Contracts
{
	/// <summary>
	/// Decorator for the <see cref="MessageServiceStrategy"/>.
	/// </summary>
	public class LoggingMessageServiceDecorator : MessageServiceStrategy
	{
		private readonly Logger myLogger = new LogFactory().GetCurrentClassLogger();
		private readonly MessageServiceStrategy myMessageServiceStrategy;
		
		/// <summary>
		/// Initializes a new instance of the <see cref="LoggingMessageServiceDecorator"/> class. 
		/// Constructor to create the decorator. Needs an implementation of <see cref="MessageServiceStrategy"/>.
		/// </summary>
		/// <param name="messageServiceStrategy">
		/// Implementation of <see cref="MessageServiceStrategy"/>.
		/// </param>
		public LoggingMessageServiceDecorator(MessageServiceStrategy messageServiceStrategy)
		{
			myMessageServiceStrategy = messageServiceStrategy;
		}
		
		/// <summary>
		/// Send the message through the <see cref="MessageServiceStrategy"/>.
		/// </summary>
		/// <param name="message">Message to send.</param>
		public override void Send(IMessage message)
		{
			myLogger.Debug("Send message with PluginGuid='{0}'.", message.PluginId);
			myMessageServiceStrategy.Send(message);
		}
	}
}
